#include "../../include/core/SavingsAccount.h"
#include "../../include/core/CheckingAccount.h"
#include <string>
#include <typeinfo>

namespace MiniBanking
{

    SavingsAccount::SavingsAccount(const std::string &accountID, const std::string &ownerName, double initialBalance)
        : BankAccount(accountID, ownerName, initialBalance) // Call base class constructor
    {
    }

    std::string SavingsAccount::getAccountType() const
    {
        return "Savings Account";
    }

    bool SavingsAccount::canTransferTo(const BankAccount &destination) const
    {
        // Rule 1: Destination must belong to the same owner
        if (destination.getOwnerName() != this->getOwnerName())
        {
            return false;
        }

        // Rule 2: Destination must be a CheckingAccount
        // Use dynamic_cast to safely check the actual type of the destination object
        // We need to check if the pointer returned by dynamic_cast is not null
        const CheckingAccount *checkingDest = dynamic_cast<const CheckingAccount *>(&destination);
        if (checkingDest != nullptr)
        {
            // It's a CheckingAccount owned by the same customer
            return true;
        }

        // If it's not a CheckingAccount or not the same owner
        return false;
    }

}
